home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
151-175
/
disk_156
/
flex
/
flex2
/
gnu.lib.src
/
xcalloc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-06
|
780b
|
35 lines
/*
* xcalloc -- a "safe" calloc
*/
char *
xcalloc (number, size)
int number, size;
{
extern char *malloc ();
extern void memory_full();
register int total = number * size;
register char *ptr = malloc (total);
if (ptr != 0)
{
if (total > 100)
bzero (ptr, total);
else {
/* It's not too long, so loop, zeroing by longs.
It must be safe because malloc values are always well aligned. */
register long *zp = (long *) ptr;
register long *zl = (long *) (ptr + total - 4);
register int i = total - 4;
while (zp < zl)
*zp++ = 0;
if (i < 0)
i = 0;
while (i < total)
ptr[i++] = 0;
}
return ptr;
}
memory_full ();
/*NOTREACHED*/
}